<?php

defined('SYSPATH') or die('Access error!');

class Controller_Store_Main extends Controller_Main
{

    public $store;
    public $store_detail;

    public function before()
    {
        parent::before();
        $this->store = Model::factory('shop_store');
        //获取店铺的模板
        $store_id = intval($this->request->param('id'));
        $this->store_detail = $this->store->get_store_by_id($store_id);
        if (Arr::validate_arr($this->store_detail))
        {
            $this->template->template_dir = ROOT_PATH . 'themes/store/' . $this->store_detail['theme'] . '/templates';
            $this->template->cache_dir = ROOT_PATH . 'themes/store/' . $this->store_detail['theme']. '/caches';
            $this->template->compile_dir = ROOT_PATH . 'themes/store/' . $this->store_detail['theme'] . '/templates_c';
            $this->template->cache_lifetime = 3600;
            $this->template->caching = FALSE;
            $this->template->media_path = 'themes/store/' .$this->store_detail['theme'] . '/templates/';
        }
        else
        {
            $this->request->redirect(Route::get('error')->uri(array('error' => 'show')));
        }
        $this->template->assign('media_path', URL::site($this->template->media_path).'/');
        Assets::css('shop_gx_style', $this->template->media_path . 'shop/css/bx_styles/bx_styles.css');
        Assets::css('shop_global', $this->template->media_path . 'shop/css/global.css');
        Assets::css('shop_home', $this->template->media_path . 'shop/css/home.css');
        Assets::js('focus', $this->template->media_path . 'shop/js/jquery.focus.js');
        Assets::js('bxslider', $this->template->media_path . 'shop/js/jquery.bxSlider.min.js');
        Assets::js('idtabs', $this->template->media_path . 'shop/js/jquery.idTabs.js');
    }
    
    public function after()
    {
        Assets::remove_css('message');
        Assets::remove_css('form');
        Assets::remove_js('message');
        Assets::remove_js('validate');
        parent::after();
    }

}